package com.java.socket;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
	@Test
	public void server() throws IOException, InterruptedException {
		ServerSocket serverSocket = new ServerSocket(5000);
		Socket socket = serverSocket.accept();

		InputStream in = socket.getInputStream();
		byte[] bytes = new byte[200];
		int length = 0;
		while(-1 != (length = in.read(bytes,0,200))){
			String str = new String(bytes,0,length);
			System.out.print(str);
		}

		OutputStream out = socket.getOutputStream();
		out.write("生我何用？不能欢笑。灭我何用？不减狂骄。".getBytes());
		in.close();
		out.close();
		socket.close();

	}
}
